﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		
    <title>模型管理</title>
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <link href="../css/Jqbox.css" rel="stylesheet" type="text/css" />
    <link href="../css/ligerui-menu.css" rel="stylesheet" type="text/css" />
    
    <link href="../css/jquery.loadmask.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery-1.5.2.min.js" type="text/javascript"></script>
    <script src="../js/ligerui.min.js" type="text/javascript"></script>
    <script src="../Js/jquery.dialog.js" type="text/javascript"></script>
    <script src="../Js/conmon.js" type="text/javascript"></script>
    <script src="../Js/jquery.loadmask.min.js" type="text/javascript"></script>

    <script src="../Js/ligerMenu.js" type="text/javascript"></script>
    <script type="text/javascript">
        var treepanel = null;
        var tree = null;
        var grid = null;
        var modelinfo = null;
        var height = 0;
        var menu = null;

        function t_hight(options) {
            // 改变树容器高度
            if (treepanel && options.middleHeight - 40 > 0)
                treepanel.setHeight(options.middleHeight - 40);
        }

        function Init_GridParams() {
            grid.setOptions({ parms: [
            { name: 'beginDate', value: $("#txtBeginDate").val() },
            { name: 'endDate', value: $("#txtEndDate").val() },
            { name: 'aid', value: $("#Aid").val() },
            { name: 'rid', value: $("#Rid").val() },
            { name: 'type', value: $("#classify").val() },
            { name: 'title', value: $("#txtTitle").val() },
            { name: 'status', value: $("#lstStatus").val() }
            ],
                newPage: 1, Rows: [], Total: 0
            });  //设置数据参数
        }

        function load_grid() {
            if (!grid) return;
            $("tbody > tr", grid.gridbody).each(function () {
                $(this).remove();
            });
            Init_GridParams();
            grid.loadData(true); //加载数据
        }

        function Search() {
            var node = tree.getSelected();
            if (node == null) {
                $("#Aid").val("-1");
                $("#Rid").val("-1");
            }
            load_grid();
        }

        //跳转考场管理
        function JmpExamManage(modelid) {
            parent.window.jmpexam(modelid);
        }

        //修改模型状态
        function SetModelSatus(id, status) {
            $("#layout1").mask("数据处理中，请稍候......");
            var params = { modelid: id, Status: status, Rnd: Math.random() };
            $.post('../WebServer/ModelManage.ashx?Action=SwitchModel', params, function (msgData) {
                var data = eval("(" + msgData + ")");
                $("#layout").unmask();
                if (data.IsSuccess == 1) {
                    //grid.loadData(true); //加载数据
                    load_grid();
                    showAlertOk("操作成功！");
                }
                else showErrorTip("操作失败，请重试！");
            });
        }

        $(function () {
            $("#txtBeginDate").ligerDateEditor({ format: "yyyy-MM-dd", width: 100 });
            $("#txtEndDate").ligerDateEditor({ format: "yyyy-MM-dd", width: 100 });


            $("#layout").ligerLayout({
                leftWidth: 200,
                height: '100%',
                onHeightChanged: t_hight
            });

            height = $(".l-layout-center").height();

            $("#treePanel").ligerAccordion({ height: height - 24, speed: null });
            treepanel = $("#treePanel").ligerGetAccordionManager();

            grid = $("#grid_model").ligerGrid({
                height: '95%',
                width: '99%',
                pageSize: 20,
                showTitle: false,
                columns: [{ display: '序号', name: 'id', width: 40, type: 'int', isSort: false,
                    render: function (item, i) {
                        i = i + 1;
                        return i;
                    }
                },
	                    { display: '模型名称', name: 'name', align: 'left', width: 150 },
	                    { display: '参考职务', name: 'rolename', align: 'left', width: 220 },
	                    { display: '创建日期', name: 'date',  dateFormat: "yyyy-MM-dd", width: 100 },
	                    { display: '模型类型', name: 'type', width: 80,
	                        render: function (row) {
	                            return (row.type == 0 ? "随机" : "手工");
	                        }
	                    },
	                    { display: '创建考场次数', name: 'exam', width: 100,
	                        render: function (row) {
	                            if (row.exam > 0)
	                            //return "<a  href='../ExamMng/ExamList.htm?modelID=" + row.id + "' >" + row.exam + " (次) </a>";
	                                return "<a onclick=' JmpExamManage(" + row.id + "); '  href='javascript:' >" + row.exam + " (次) </a>";
	                            else
	                                return row.exam + " (次)";
	                        }
	                    },
	                    { display: '状态', name: 'status', width: 60,
	                        render: function (row) {
	                            return (row.status == 0 ? "√" : "×");
	                        }
	                    },
                        { display: '总分', name: 'model_score', width: 50 },
                        { display: '启/停用', width: 80,
                            render: function (row) {
                                return (row.status == 0 ?
                                "<a   onclick='SetModelSatus(" + row.id + ", 1)' href='javascript:' >停用</a>" :
                                "<a   onclick='SetModelSatus(" + row.id + ", 0)' href='javascript:' >启用</a>");
                            }
                        }
                        , { display: '查看', name: 'id', isSort: false, width: 50,
                            render: function (item) {
                                return "<a onclick='ViewModel(" + item.id + "," + item.type + ");' href='javascript:' >查看</a>";
                            }
                        }
                        ],
                parms: [
                                { name: 'beginDate', value: $("#txtBeginDate").val() },
                                { name: 'endDate', value: $("#txtEndDate").val() },
                                { name: 'aid', value: $("#Aid").val() },
                                { name: 'rid', value: $("#Rid").val() },
                                { name: 'type', value: $("#classify").val() },
                                { name: 'title', value: $("#txtTitle").val() },
                                { name: 'status', value: $("#lstStatus").val() }
                               ],
                newPage: 1, Rows: [], Total: 0,
                dataAction: 'server',
                url: '../WebServer/ModelManage.ashx?Action=ModelGrid&rnd=' + Math.random().toString(),
                onDblClickRow: function (data, rowindex, rowobj) {
                    $("#modelID").val(data.id);
                    $("#modelName").val(data.name);
                    ShowDialog("ExamMng/EditExam.htm", "编辑", 600, 350);
                }
            });

            menu = $.ligerMenu({
                top: 100,
                left: 100,
                width: 120,
                items: [
						{ text: '随机模型', value: 'random', click: itemclick },
						{ text: '手工模型', value: 'manual', click: itemclick }
					]
            });

            tree = $("#tree").ligerTree({
                checkbox: true,
                slide: false,
                nodeWidth: 100,
                url: "../WebServer/ModelManage.ashx?Action=AreRoleTree&rnd=" + Math.random(),
                // 单击
                onSelect: function (node, e) {
                    $("#Aid").val(node.data.areid);
                    $("#Rid").val(node.data.value);
                    $("#roleName").val(node.data.text);
                    $("#classify").val(-1);
                    $("#areRoleID").val(node.data.areRoleID);
                    $("#txtBeginDate").val("");
                    $("#txtEndDate").val("");
                    $("#txtTitle").val("");
                    load_grid();
                }
            });

            $("#create").click(function (e) {
                menu.show({ top: e.pageY, left: e.pageX });
                return false;
            })

            $('#export').click(function (e) {
                exportUrl = "../WebServer/DownloadExcel.ashx?Action=ExportModel"
                       + "&aid=" + $("#Aid").val()
                       + "&rid=" + $("#Rid").val()
                       + "&type=" + $("#classify").val()
                       + "&beginDate=" + $("#txtBeginDate").val()
                       + "&endDate=" + $("#txtEndDate").val()
                       + "&title=" + $("#txtTitle").val()
                       + "&status=" + $("#lstStatus").val();
                window.open(exportUrl, "_blank");
            });

            $("#pageloading").hide();
        });

        function ViewModel(modelID, type) {
            $("#modelID").val(modelID);
            if (type == 0)
                ShowDialog("model/RandomModelDetail.htm", "查看随机模型", 600, 400);
            else
                ShowDialog("model/ManualModelDetail.htm", "查看手工模型", 900, 400);
        }

        // 检查树选中参数.
        function check_param() {
            chkAreRoleIDs = $("#chkAreRoleIDs").val();
            chkAreRoleNames = $("#chkAreRoleNames").val();

            if (chkAreRoleIDs[chkAreRoleIDs.length - 1] == ',')
                chkAreRoleIDs = chkAreRoleIDs.substring(0, chkAreRoleIDs.length - 1);

            if (chkAreRoleNames[chkAreRoleNames.lenth - 1] == ',')
                chkAreRoleNames = chkAreRoleNames.subject(0, chkAreRoleNames.length - 1);

            var are_role_id = chkAreRoleIDs.split(',');
            var are_role_name = chkAreRoleNames.split(',');
        }

        // 鼠标点击
        function itemclick(item, i) {
            GetCheckedAreRoles();
            var roleID = parseInt($("#Rid").val());
            if (($("#Rid").val() == "" || roleID == -1 || roleID == 0) && $("#chkAreRoleIDs").val() == "") {
                showErrorTip("请选择区域职务后在增加模型！");
                return;
            }
            switch (item.value) {
                case 'random':
                        ShowDialog('model/randommodel.htm', "随机模型", 800, 550);
                        break;
                case 'manual':
                    ShowDialog('model/manualmodel.htm', "手工模型", 800, 550);
                    break;
            }
        }

        //是否选择同一个角色(默认是)
        var chkSameRole = true;
        //获取选择的节点
        function GetCheckedAreRoles() {
            var notes = tree.getChecked();
            var chkIDs = "";
            var chkNames = "";
            
            var chkrole = "";
            var chkare = "";
            var count = 0;
            //判断是否选择同一个角色
            chkSameRole = true;
            var oldChkRoleID = -1;
            for (var i = 0; i < notes.length; i++) {
                if (parseInt(notes[i].data.value) == -1)
                    continue;

                count++;
                chkrole = notes[i].data.value;
                chkare = notes[i].data.areid;

                if (oldChkRoleID == -1)
                    oldChkRoleID = parseInt(chkrole);
                else {
                    if (oldChkRoleID != parseInt(chkrole))
                        chkSameRole = false;
                }

                chkIDs = chkIDs + notes[i].data.areRoleID + ",";
                if (chkNames.indexOf(notes[i].data.text + ",") == -1)
                    chkNames = chkNames + notes[i].data.text + ",";
            }

            if (count == 1) {
                $("#Rid").val(chkrole);
                $("#Aid").val(chkare);
                $("#areRoleID").val(chkIDs.substring(0, chkIDs.length - 1));
                $("#roleName").val(chkNames.substring(0, chkNames.length - 1));

                $("#chkAreRoleIDs").val("");
                $("#chkAreRoleNames").val("");
            }
            else {
                $("#chkAreRoleIDs").val(chkIDs);
                $("#chkAreRoleNames").val(chkNames);
                //如果默认选中的是同一角色
                if (chkSameRole) {
                    if (chkrole != "") {
                        $("#Rid").val(chkrole);
                        $("#roleName").val(chkNames.substring(0, chkNames.length - 1));
                    }
                }
            }
        }


        
    </script>
     <style type="text/css"> 
 
            body{ padding:5px; margin:0; padding-bottom:15px;}
            #layout1{  width:100%;margin:0; padding:0;  }  
            .l-page-top{ height:80px; background:#f8f8f8; margin-bottom:3px;}
            h4{ margin:20px;}
  </style>
</head>
<body style="padding:10px">

<div id="layout">
            <div position="left">
            	<div id="treePanel" style="width:100%;  overflow: auto;  ">
            		<ul id="tree"></ul>
            	</div>
            </div>
            
            <div position="center">
                <table border="0" cellspacing="0" cellpadding="0" width="100%">
			        <tr>
				        <td style="background: #E5EDEF; padding-left:5px; padding-top:3px;" width="80">起始日期:</td>
				        <td style="background: #E5EDEF; padding-left:5px; padding-top:3px;" width="120"> <input id="txtBeginDate" type="text" ltype="text" /></td>
				
				        <td style="background: #E5EDEF; padding-left:5px; padding-top:3px;" width="80">模型名称:</td>
				        <td colspan="3" style="background: #E5EDEF; padding-left:5px; padding-top:3px;" width="120"><input id="txtTitle" type="text" class="l-text" style="width:200px;" /></td>
				
				        <td rowspan="2" style="background: #E5EDEF; padding-left:5px; padding-top:3px;" width="80">
                            <div class="l-button" style="width: 60px; height:30px; padding-top:13px;" onclick="Search()">查寻</div>
                        </td>
				
				        <td style="background: #E5EDEF; padding-left:5px; padding-top:3px;"><a  id="export" class="l-button" style="width:70px; float:left; margin-left:10px;">模型导出</a></td>
			        </tr>
			        <tr>
				        <td style="background: #E5EDEF; padding-left:5px; padding-top:3px;" width="80">结束日期:</td>
				        <td style="background: #E5EDEF; padding-left:5px; padding-top:3px;" width="120"><input id="txtEndDate" type="text" ltype="text" /></td>
				
				        <td style="background: #E5EDEF; padding-left:5px; padding-top:3px;" width="80">模型类型</td>
				        <td style="background: #E5EDEF; padding-left:5px; padding-top:3px;" width="60">
                            <select id="classify">
                                <option value="-1" title="全部" selected="selected">全部</option>
                                <option value="0">随机</option>
                                <option value="1">手工</option>
                            </select>
                        </td>
				
				        <td style="background: #E5EDEF; padding-left:5px; padding-top:3px;" width="80">模型状态</td>
				        <td style="background: #E5EDEF; padding-left:5px; padding-top:3px;" width="60">
                           <select id="lstStatus">
                                <option value="-1" title="全部" selected="selected">全部</option>
                                <option value="0">启用</option>
                                <option value="1">停用</option>
                            </select>
                        </td>
				
				        <td style="background: #E5EDEF; padding-left:5px; padding-top:3px;"><a  id="create" class="l-button" style="width:70px; float:left; margin-left:10px;">新建模型</a></td>
			        </tr>

		    </table>
            <div id="grid_model"></div>
        
                   
            </div>  
</div>
   <input type="hidden" id="Aid" value="-1" />
   <input type="hidden" id="Rid" value="-1" />
   <input type="hidden" id="roleName" value="0" />
   <input type="hidden" id="areRoleID" value="0" />
   <input type="hidden" id="modelID" value="0" />
   <input type="hidden" id="modelName" />
   <input type="hidden" id="chkAreRoleIDs" value="" />
   <input type="hidden" id="chkAreRoleNames" value="" />
</body>
</html>


